package org.example.rabbitmq.product.config.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hzq
 * @date 2021/11/24 14:21
 */
@Configuration
public class RabbitmqBindingConfiguration {

    @Bean
    public Binding directQueueOneBindingDirectExchange(Queue directQueueOne, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueueOne).to(directExchange).withQueueName();
    }

    @Bean
    public Binding twoQueueDirectBindingDirectExchange(Queue twoQueueDirect, DirectExchange directExchange) {
        return BindingBuilder.bind(twoQueueDirect).to(directExchange).withQueueName();
    }

    @Bean
    public Binding queueFanoutOneBindingFanoutExchange(Queue queueFanoutOne, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queueFanoutOne).to(fanoutExchange);
    }

    @Bean
    public Binding fanoutQueueTwoBindingFanoutExchange(Queue fanoutQueueTwo, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueueTwo).to(fanoutExchange);
    }

    @Bean
    public Binding oneQueueTopicBindingTopicExchange(Queue oneQueueTopic, TopicExchange topicExchange) {
        return BindingBuilder.bind(oneQueueTopic).to(topicExchange).with("*.queue.topic");
    }

    @Bean
    public Binding topicQueueTwoBindingTopicExchange(Queue topicQueueTwo, TopicExchange topicExchange) {
        return BindingBuilder.bind(topicQueueTwo).to(topicExchange).with("topic.queue.*");
    }

    @Bean
    public Binding delayQueueBindingDirectExchange(Queue delayQueue, DirectExchange directExchange) {
        return BindingBuilder.bind(delayQueue).to(directExchange).withQueueName();
    }

    /**
     * 延迟队列绑定自定义交换器
     *
     * @param customDelayQueue 队列
     * @param delayExchange    延迟交换器
     */
//    @Bean
//    public Binding customDelayQueueBindingDelayExchange(Queue customDelayQueue, CustomExchange delayExchange) {
//        return BindingBuilder.bind(customDelayQueue).to(delayExchange).with("custom.delay.queue").noargs();
//    }

}
